home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 34
/
Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso
/
-seriously_amiga-
/
programming
/
c
/
mesa-2.6
/
src-glu
/
nurbs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-10-01
|
21KB
|
675 lines
/* $Id: nurbs.c,v 1.11 1998/02/07 14:29:11 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 2.6
* Copyright (C) 1995-1997 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* nurbs.c
*
* Version 1.0 27 Jun 1998
* by Jarno van der Linden
* jarno@kcbbs.gen.nz
*
* File created from nurbs.c ver 1.11 and glu.h ver 1.9 using GenProtos
*
*/
/*
* NURBS implementation written by Bogdan Sikorski (bogdan@cira.it)
* See README2 for more info.
*/
#ifdef PC_HEADER
#include "all.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include "gluP.h"
#include "nurbs.h"
#endif
void
call_user_error( GLUnurbsObj *nobj, GLenum error )
{
nobj->error=error;
if(nobj->error_callback != NULL) {
(*(nobj->error_callback))(error);
}
else {
printf("NURBS error %d %s\n", error, gluErrorString(error) );
}
}
__asm __saveds GLUnurbsObj * APIENTRY gluNewNurbsRenderer( void )
{
GLUnurbsObj *n;
GLfloat tmp_viewport[4];
GLint i,j;
n = (GLUnurbsObj *) malloc( sizeof(GLUnurbsObj) );
if (n) {
/* init */
n->culling=GL_FALSE;
n->nurbs_type=GLU_NURBS_NONE;
n->error=GLU_NO_ERROR;
n->error_callback=NULL;
n->auto_load_matrix=GL_TRUE;
n->sampling_tolerance=50.0;
n->parametric_tolerance=0.5;
n->u_step = n->v_step = 100;
n->sampling_method = GLU_PATH_LENGTH;
n->display_mode=GLU_FILL;
/* in case the user doesn't supply the sampling matrices */
/* set projection and modelview to identity */
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(i==j)
{
n->sampling_matrices.model[i*4+j]=1.0;
n->sampling_matrices.proj[i*4+j]=1.0;
}
else
{
n->sampling_matrices.model[i*4+j]=0.0;
n->sampling_matrices.proj[i*4+j]=0.0;
}
/* and set the viewport sampling matrix to current ciewport */
glGetFloatv(GL_VIEWPORT,tmp_viewport);
for(i=0;i<4;i++)
n->sampling_matrices.viewport[i]=tmp_viewport[i];
n->trim=NULL;
}
return n;
}
__asm __saveds void APIENTRY gluDeleteNurbsRenderer( register __a0 GLUnurbsObj *nobj )
{
if (nobj) {
free( nobj );
}
}
__asm __saveds void APIENTRY gluLoadSamplingMatrices( register __a0 GLUnurbsObj *nobj,
register __a1 const GLfloat modelMatrix[16],
register __a2 const GLfloat projMatrix[16],
register __a3 const GLint viewport[4] )
{
GLint i;
for(i=0;i<16;i++)
{
nobj->sampling_matrices.model[i]=modelMatrix[i];
nobj->sampling_matrices.proj[i]=projMatrix[i];
}
for(i=0;i<4;i++)
nobj->sampling_matrices.viewport[i]=viewport[i];
}
__asm __saveds void APIENTRY gluNurbsProperty( register __a0 GLUnurbsObj *nobj, register __d0 GLenum property, register __fp0 GLfloat value )
{
GLenum val;
switch (property) {
case GLU_SAMPLING_TOLERANCE:
if(value <= 0.0)
{
call_user_error(nobj,GLU_INVALID_VALUE);
return;
}
nobj->sampling_tolerance=value;
break;
case GLU_PARAMETRIC_TOLERANCE:
if(value <= 0.0)
{
call_user_error(nobj,GLU_INVALID_VALUE);
return;
}
nobj->parametric_tolerance=value;
break;
case GLU_U_STEP:
if(value <= 0.0)
{
call_user_error(nobj,GLU_INVALID_VALUE);
return;
}
nobj->u_step=(GLint)value;
break;
case GLU_V_STEP:
if(value <= 0.0)
{
call_user_error(nobj,GLU_INVALID_VALUE);
return;
}
nobj->v_step=(GLint)value;
break;
case GLU_SAMPLING_METHOD:
val = (GLenum)value;
if(val!=GLU_PATH_LENGTH && val!=GLU_PARAMETRIC_ERROR && val!=GLU_DOMAIN_DISTANCE)
{
call_user_error(nobj,GLU_INVALID_ENUM);
return;
}
nobj->sampling_method=val;
break;
case GLU_DISPLAY_MODE:
val=(GLenum)value;
if(val!=GLU_FILL && val!=GLU_OUTLINE_POLYGON && val!=GLU_OUTLINE_PATCH)
{
call_user_error(nobj,GLU_INVALID_ENUM);
return;
}
if(nobj->nurbs_type==GLU_NURBS_CURVE)
{
call_user_error(nobj,GLU_NURBS_ERROR26);
return;
}
nobj->display_mode=val;
if(val==GLU_OUTLINE_PATCH)
fprintf(stderr,"NURBS, for the moment, can display only in POLYGON mode\n");
break;
case GLU_CULLING:
val=(GLenum)value;
if(val!=GL_TRUE && val!=GL_FALSE)
{
call_user_error(nobj,GLU_INVALID_ENUM);
return;
}
nobj->culling = (GLboolean) value;
break;
case GLU_AUTO_LOAD_MATRIX:
val=(GLenum)value;
if(val!=GL_TRUE && val!=GL_FALSE)
{
call_user_error(nobj,GLU_INVALID_ENUM);
return;
}
nobj->auto_load_matrix = (GLboolean) value;
break;
default:
call_user_error(nobj,GLU_NURBS_ERROR26);
}
}
__asm __saveds void APIENTRY gluGetNurbsProperty( register __a0 GLUnurbsObj *nobj, register __d0 GLenum property, register __a1 GLfloat *value )
{
switch (property) {
case GLU_SAMPLING_TOLERANCE:
*value = nobj->sampling_tolerance;
break;
case GLU_DISPLAY_MODE:
*value = (GLfloat) (GLint) nobj->display_mode;
break;
case GLU_CULLING:
*value = nobj->culling ? 1.0 : 0.0;
break;
case GLU_AUTO_LOAD_MATRIX:
*value = nobj->auto_load_matrix ? 1.0 : 0.0;
break;
default:
call_user_error(nobj,GLU_INVALID_ENUM);
}
}
__asm __saveds void APIENTRY gluBeginCurve( register __a0 GLUnurbsObj *nobj )
{
if(nobj->nurbs_type==GLU_NURBS_CURVE)
{
call_user_error(nobj,GLU_NURBS_ERROR6);
return;
}
nobj->nurbs_type=GLU_NURBS_CURVE;
nobj->curve.geom.type=GLU_INVALID_ENUM;
nobj->curve.color.type=GLU_INVALID_ENUM;
nobj->curve.texture.type=GLU_INVALID_ENUM;
nobj->curve.normal.type=GLU_INVALID_ENUM;
}
__asm __saveds void APIENTRY gluEndCurve( register __a0 GLUnurbsObj * nobj )
{
if(nobj->nurbs_type==GLU_NURBS_NONE)
{
call_user_error(nobj,GLU_NURBS_ERROR7);
return;
}
if(nobj->curve.geom.type==GLU_INVALID_ENUM)
{
call_user_error(nobj,GLU_NURBS_ERROR8);
nobj->nurbs_type=GLU_NURBS_NONE;
return;
}
glPushAttrib( (GLbitfield) (GL_EVAL_BIT | GL_ENABLE_BIT) );
glDisable(GL_MAP1_VERTEX_3);
glDisable(GL_MAP1_VERTEX_4);
glDisable(GL_MAP1_INDEX);
glDisable(GL_MAP1_COLOR_4);
glDisable(GL_MAP1_NORMAL);
glDisable(GL_MAP1_TEXTURE_COORD_1);
glDisable(GL_MAP1_TEXTURE_COORD_2);
glDisable(GL_MAP1_TEXTURE_COORD_3);
glDisable(GL_MAP1_TEXTURE_COORD_4);
glDisable(GL_MAP2_VERTEX_3);
glDisable(GL_MAP2_VERTEX_4);
glDisable(GL_MAP2_INDEX);
glDisable(GL_MAP2_COLOR_4);
glDisable(GL_MAP2_NORMAL);
glDisable(GL_MAP2_TEXTURE_COORD_1);
glDisable(GL_MAP2_TEXTURE_COORD_2);
glDisable(GL_MAP2_TEXTURE_COORD_3);
glDisable(GL_MAP2_TEXTURE_COORD_4);
do_nurbs_curve(nobj);
glPo